import { type HosDetailType } from "@/api/hospitalList";
import { reqHosDetail } from "@/api/hospitalList";
import { Card, Descriptions } from "antd";
import React, { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";

export default function HospitalDetail() {
  const location = useLocation();
  const id = (location.state as any).id;
  console.log(id);

  //数据1 医院详情
  const [hosDetail, setHosDetail] = useState<HosDetailType>();

  useEffect(() => {
    const getHosDetail = async () => {
      const result = await reqHosDetail(id);
      setHosDetail(result);
    };
    getHosDetail();
    console.log(hosDetail);
  }, []);

  return (
    <Card>
      <Descriptions title="基本信息" bordered column={2}>
        <Descriptions.Item label="医院名称">
          {hosDetail?.hospital.hosname}
        </Descriptions.Item>
        <Descriptions.Item label="医院logo">
          {hosDetail?.hospital.logoData && (
            <img
              src={"data:image/jpge;base64," + hosDetail?.hospital.logoData}
              width="100px"
            />
          )}
        </Descriptions.Item>
        <Descriptions.Item label="医院编码">
          {hosDetail?.hospital.hoscode}
        </Descriptions.Item>
        <Descriptions.Item label="医院地址">
          {hosDetail?.hospital.param.fullAddress}
        </Descriptions.Item>
        <Descriptions.Item label="坐车路线" span={2}>
          {hosDetail?.hospital.route}
        </Descriptions.Item>
        <Descriptions.Item label="医院简介" span={2}>
          {hosDetail?.hospital.intro}
        </Descriptions.Item>
      </Descriptions>
      <Descriptions
        title="预约规则信息"
        bordered
        column={2}
        style={{ marginTop: "40px" }}
      >
        <Descriptions.Item label="预约周期">
          {hosDetail?.bookingRule.cycle}
        </Descriptions.Item>
        <Descriptions.Item label="放号时间">
          {hosDetail?.bookingRule.releaseTime}
        </Descriptions.Item>
        <Descriptions.Item label="停接时间">
          {hosDetail?.bookingRule.stopTime}
        </Descriptions.Item>
        <Descriptions.Item label="退号时间">
          {hosDetail?.bookingRule.quitTime}
        </Descriptions.Item>
        <Descriptions.Item label="预约规则" span={2}>
          {hosDetail?.bookingRule.rule.map((item, index) => {
            return <div key={index}>{item}</div>;
          })}
        </Descriptions.Item>
      </Descriptions>
    </Card>
  );
}
